package com.example.service.flowable.impl;
import com.example.service.flowable.FlowableGeneralService;
import lombok.extern.slf4j.Slf4j;
import org.flowable.bpmn.model.BpmnModel;
import org.flowable.common.engine.impl.util.IoUtil;
import org.flowable.engine.RepositoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.OutputStream;

/**
 * flowable通用服务实现类
 * @author wsl
 */
@Service
@Slf4j
public class FlowableGeneralServiceImpl implements FlowableGeneralService {

    @Autowired
    private RepositoryService repositoryService;

//    @Autowired
//    private  ;

    @Override
    public void picResourceView(String processDefinitionId, String processInstanceId, HttpServletResponse response) {
        // 获取流程图
//        BpmnModel bpmnModel = repositoryService.getBpmnModel(processDefinitionId);
//        ProcessEngineConfiguration engConf = processEngine.getProcessEngineConfiguration();
//        ProcessDiagramGenerator diagramGenerator = new CustomProcessDiagramGenerator();
//        InputStream in = diagramGenerator.generateDiagram(bpmnModel, "bmp", Collections.EMPTY_LIST, Collections.EMPTY_LIST, engConf.getActivityFontName(),
//                engConf.getLabelFontName(), engConf.getAnnotationFontName(), engConf.getClassLoader(), 1.0, true);
//        OutputStream out = null;
//        byte[] buf = new byte[1024];
//        int length;
//        try {
//            out = response.getOutputStream();
//            while ((length = in.read(buf)) != -1) {
//                out.write(buf, 0, length);
//            }
//        } catch (IOException e) {
//            log.error("操作异常", e);
//        } finally {
//            IoUtil.closeSilently(out);
//            IoUtil.closeSilently(in);
//        }
    }
}
